package graph;

import java.util.Objects;

/**
 * 图的边
 */
public class Edge<T> {
    /**
     * 边的权重
     */
    int weight;

    /**
     * from、to限定的方向，表示当前边是从from指向to
     */
    Node<T> from;
    Node<T> to;

    public Edge() {
    }

    public Edge(int weight, Node<T> from, Node<T> to) {
        this.weight = weight;
        this.from = from;
        this.to = to;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Edge<?> edge = (Edge<?>) o;
        return Objects.equals(from, edge.from) && Objects.equals(to, edge.to);
    }

    @Override
    public int hashCode() {
        return Objects.hash(from, to);
    }
}
